<div ng-show="vm.notFoundMessage" class="alert alert-warning" role="alert">{{ vm.notFoundMessage }}</div>
<loading-indicator hide="vm.user || vm.notFoundMessage"></loading-indicator>

<div class="text-center" ng-hide="!vm.user || vm.notFoundMessage">
	<h2><user user="::vm.user" show-class="false" icon-size="big" link="false"></user> <span ng-bind-html="vm.user.gender | genderIcon"></span> <button ng-if="vm.currentUser.class >= 8" ui-sref="edit-user({id: vm.user.id, username: vm.user.username})" class="btn btn-default btn-xs"><i class="fa fa-cog"></i></button></h2>
</div>
<div class="row row-centered" ng-cloak>
<div ng-class="{'col-lg-12': vm.showPeers || vm.showBonuslog || vm.showInvites || vm.showRequests || vm.showTorrents || vm.showSnatchLog || vm.showIpLog, 'col-lg-10': !vm.showPeers && !vm.showBonuslog && !vm.showInvites && !vm.showRequests && !vm.showTorrents && !vm.showSnatchLog && !vm.showIpLog}" class="table-responsive noborder col-centered" ng-show="vm.user">
	<table class="table" cellpadding="15">
		<tr>
			<td style="width: 150px;" class="text-right tdBold alignMiddle" translate="USER.MEMBER_SINCE"></td>
			<td class="text-left">{{ vm.user.added }} ({{ vm.user.added | dateDifference }} {{ 'MAILBOX.AGO' | translate }})</td>
		</tr>
		<tr>
			<td class="text-right tdBold alignMiddle" translate="FRIENDS.LAST_SEEN"></td>
			<td class="text-left">{{ vm.user.last_access }} ({{ vm.user.last_access | dateDifference }} {{ 'MAILBOX.AGO' | translate }})</td>
		</tr>
		<tr ng-if="vm.user.ip">
			<td class="text-right tdBold alignMiddle" translate="ADMIN.IP"></td>
			<td class="text-left"><a href="" ui-sref="admin-search({ip: vm.user.ip})">{{ vm.user.ip }}</a></td>
		</tr>
		<tr ng-if="vm.currentUser.class >= 8 && vm.user.torrentip">
			<td class="text-right tdBold alignMiddle" translate="USER.TORRENT_IP"></td>
			<td class="text-left"><a href="" ui-sref="admin-search({ip: vm.user.torrentip})">{{ vm.user.torrentip }}</a></td>
		</tr>
		<tr ng-if="vm.currentUser.id == vm.user.id || vm.currentUser.class >= 8">
			<td class="text-right tdBold">
				<button class="btn btn-default btn-xs" ng-click="vm.toggleIpLog()">
					<i class="fa fa-bars"></i> {{ 'USER.SHOW_IP_LOG' | translate }}
				</button>
			</td>
			<td class="text-left">
				<div ng-show="vm.showIpLog && !vm.iplog" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
				<div ng-show="vm.showIpLog && vm.iplog">
					<table class="table table-striped table-hover table-nowrap table-text-center">
						<thead>
							<tr>
								<th style="width: 250px; text-align: left;" translate="FRIENDS.LAST_SEEN"></th>
								<th style="text-align: left;" translate="ADMIN.IP_HOST"></th>
								<th style="text-align: left; width: 125px;" translate="USER.USAGE"></th>
								<th style="text-align: center; width: 80px;" ng-if="vm.currentUser.class >= 8" translate="BUTTONS.DELETE"></th>
							</tr>
						</thead>
						<tbody>
							<tr ng-repeat="ip in vm.iplog track by ip.id">
								<td style="text-align: left;">{{ ::ip.lastseen }} ({{ ::ip.lastseen | dateDifference }} {{ 'MAILBOX.AGO' | translate }})</td>
								<td style="text-align: left;"><a href="" ui-sref="admin-search({ip: vm.user.ip})">{{ ::ip.ip }}</a> (<b>{{ ::ip.host}}</b>)</td>
								<td style="text-align: left;">{{ ::ip.uptime*1000 | dateDifference:0}}</td>
								<td style="text-align: center;" ng-if="vm.currentUser.class >= 8"><button class="btn btn-default btn-xs" ng-click="vm.deleteIPLog(ip);"><i class="fa fa-trash-o"></i></button></td>
							</tr>
						</tbody>
					</table>
					<br />
					<div class="block-center text-center" ng-show="vm.iplog">
						<button class="btn btn-default btn-xs" ng-click="vm.toggleIpLog(true)">
							<i class="fa fa-bars"></i> {{ 'USER.LOAD_FULL_LOG' | translate }}
						</button>
					</div>
				</div>
			</td>
		</tr>
		<tr ng-show="vm.user.age">
			<td class="text-right tdBold alignMiddle" translate="SIGNUP.AGE"></td>
			<td class="text-left">{{ ::vm.user.age }}</td>
		</tr>
		<tr ng-show="vm.user.invitees">
			<td class="text-right tdBold">
				<button class="btn btn-default btn-xs" ng-click="vm.toggleInvites()">
					<i class="fa fa-bars"></i> {{ 'INVITE.SHOW_INVITED' | translate }}
				</button>
			</td>
			<td class="text-left">
				<span translate="USER.X_USERS" translate-value-x="{{ ::vm.user.invitees }}"></span>
				<div ng-show="vm.showInvites && !vm.invitees" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
				<table class="table table-striped table-hover table-text-center table-nowrap" ng-show="vm.showInvites && vm.invitees">
					<thead>
						<tr>
							<th style="text-align: left;">&nbsp;<a class="whiteLink" href="" ng-click="invitesOrderBy='username'; reverseSort = !reverseSort" translate="USER.NAME"></a></th>
							<th style="width: 90px;"><a class="whiteLink" href="" ng-click="invitesOrderBy='uploaded'; reverseSort = !reverseSort" translate="TORRENTS.UPLOADED"></a></th>
							<th style="width: 90px;"><a class="whiteLink" href="" ng-click="invitesOrderBy='downloaded'; reverseSort = !reverseSort"  translate="TORRENTS.DOWNLOADED"></a></th>
							<th style="width: 90px;" translate="STATUS.RATIO"></th>
							<th style="width: 250px; text-align: left;"><a class="whiteLink" href="" ng-click="invitesOrderBy='last_access'; reverseSort = !reverseSort" translate="FRIENDS.LAST_SEEN"></a></th>
						</tr>
					</thead>
					<tbody>
						<tr ng-repeat="invitee in vm.invitees | orderBy:invitesOrderBy:reverseSort track by invitee.id">
							<td style="text-align: left;">
								<user user="::invitee"></user>
							</td>
							<td>{{ ::invitee.uploaded | prettysize }}</td>
							<td>{{ ::invitee.downloaded | prettysize }}</td>
							<td ng-bind-html="invitee.uploaded / invitee.downloaded | ratio"></td>
							<td style="text-align: left;">{{ ::invitee.last_access }} ({{ ::invitee.last_access | dateDifference }} {{ 'MAILBOX.AGO' | translate }})</td>
						</tr>
					</tbody>
				</table>
			</td>
		</tr>
		<tr ng-if="vm.currentUser.id == vm.user.id || vm.currentUser.class >= 8">
			<td class="text-right tdBold">
				<button class="btn btn-default btn-xs" ng-click="vm.toggleBonusLog()">
					<i class="fa fa-bars"></i> {{ 'USER.SHOW_BONUS_LOG' | translate }}
				</button>
			</td>
			<td class="text-left">
				<div ng-show="vm.showBonuslog && !vm.bonuslog" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
				<div ng-show="vm.showBonuslog && vm.bonuslog">
					<table class="table table-striped table-hover table-text-center">
						<thead>
							<tr>
								<th style="width: 150px;">&nbsp;{{ 'TORRENTS.DATE' | translate}}</th>
								<th class="text-left" translate="MAILBOX.MESSAGE"></th>
							</tr>
						</thead>
						<tbody>
							<tr ng-repeat="bonusline in vm.bonuslog track by bonusline.id">
								<td>{{ ::bonusline.datum | date }}</td>
								<td class="text-left" ng-bind-html="::bonusline.msg | bbCode"></td>
							</tr>
						</tbody>
					</table>
					<br />
					<div class="block-center text-center" ng-show="vm.bonuslog">
						<button class="btn btn-default btn-xs" ng-click="vm.toggleBonusLog(true)">
							<i class="fa fa-bars"></i> {{ 'USER.LOAD_FULL_LOG' | translate }}
						</button>
					</div>
				</div>
			</td>
		</tr>
		<tr ng-show="vm.user.isp || vm.user.mbitner || vm.user.mbitupp">
			<td class="text-right tdBold alignMiddle" translate="USER.BANDWIDTH"></td>
			<td class="text-left">
				<span ng-show="vm.user.mbitner > 0">{{ 'USER.DOWNSTREAM' | translate }}: <b>{{ ::vm.user.mbitner }} {{ 'USER.MBIT' | translate }}</b></span>
				<span ng-show="vm.user.mbitupp > 0">{{ 'USER.UPSTREAM' | translate }}: <b>{{ ::vm.user.mbitupp }} {{ 'USER.MBIT' | translate }}</b></span>
				<span ng-show="::vm.user.isp">{{ 'USER.ISP' | translate }}: <b>{{ ::vm.user.isp }}</b></span>
			</td>
		</tr>
		<tr ng-if="vm.user.uploaded !== null">
			<td class="text-right tdBold alignMiddle" translate="TORRENTS.UPLOADED"></td>
			<td class="text-left">{{ ::vm.user.uploaded | prettysize }}</td>
		</tr>
		<tr ng-if="vm.user.downloaded !== null">
			<td class="text-right tdBold alignMiddle" translate="TORRENTS.DOWNLOADED"></td>
			<td class="text-left">{{ ::vm.user.downloaded | prettysize }} ({{ ::vm.user.downloaded_real | prettysize }})</td>
		</tr>
		<tr ng-if="vm.user.uploaded !== null">
			<td class="text-right tdBold alignMiddle" translate="STATUS.RATIO"></td>
			<td class="text-left" ng-bind-html="vm.user.uploaded / vm.user.downloaded | ratio"></td>
		</tr>
		<tr ng-hide="vm.user.leechbonus == undefined">
			<td class="text-right tdBold alignMiddle" translate="LEECHBONUS.TITLE"></td>
			<td class="text-left">
				<div class="row">
					<div class="col-sm-4"><uib-progressbar class="progress-striped active" value="::vm.user.leechbonus" type="warning">{{ ::vm.user.leechbonus }}%</uib-progressbar>
					</div>
				</div>
			</td>
		</tr>
		<tr ng-show="vm.user.class > 0">
			<td class="text-right tdBold alignMiddle" translate="STATUS.BONUS"></td>
			<td class="text-left"><b>{{ ::vm.user.bonuspoang }}p</b> <span ng-show="vm.currentUser.id == vm.user.id || vm.currentUser.class >= 8" translate="USER.BONUS_STATUS" translate-value-uploaded="{{ :: vm.user.nytt_seed+vm.user.arkiv_seed | prettysize }}" translate-value-new="{{ ::vm.user.nytt_seed | prettysize }}" translate-value-archive="{{ ::vm.user.arkiv_seed | prettysize }}"></span></td>
		</tr>
		<tr ng-show="vm.user.invitedByUser">
			<td class="text-right tdBold alignMiddle" translate="USER.INVITED_BY"></td>
			<td class="text-left"><user user="::vm.user.invitedByUser"></user></td>
		</tr>
		<tr ng-show="vm.user.avatar">
			<td class="text-right tdBold" translate="USER.AVATAR"></td>
			<td class="text-left"><img ng-src="{{ ::vm.user.avatar }}" style="max-width: 150px;" /></td>
		</tr>
		<tr ng-show="vm.user.hearts > 0">
			<td class="text-right tdBold" translate="USER.HEARTS"></td>
			<td class="text-left" style="font-size: 18px; color: #E80000;"><span  ng-repeat="_ in ((_ = []) && (_.length=vm.user.hearts||0) && _) track by $index"><i class="fa fa-heart"></i> </span></td>
		</tr>
		<tr>
			<td class="text-right tdBold alignMiddle" translate="USER.CLASS_LEVEL"></td>
			<td class="text-left">{{ ::vm.user.class | userClass }} <span ng-if="::vm.user.title"> | {{ ::vm.user.title }}</span></td>
		</tr>
		<tr ng-if="vm.currentUser.id == vm.user.id || vm.currentUser.class >= 8">
			<td class="text-right tdBold alignMiddle" translate="USER.TORRENT_COMMENTS"></td>
			<td class="text-left"><a href="" ui-sref="user-comments({id: vm.user.id, username: vm.user.username})">{{::vm.user.torrentComments }}</a></td>
		</tr>
		<tr ng-if="vm.currentUser.id == vm.user.id || vm.currentUser.class >= 8">
			<td class="text-right tdBold alignMiddle" translate="ADMIN.FORUM_POSTS"></td>
			<td class="text-left"><a href="" ui-sref="forum-user-posts({id: vm.user.id, username: vm.user.username})">{{ ::vm.user.forumPosts }}</a></td>
		</tr>
		<tr ng-hide="vm.currentUser.id == vm.user.id" >
			<td class="text-right alignMiddle tdBold" translate="USER.FUNCTIONS"></td>
			<td class="text-left">
				<button class="btn btn-xs btn-default" ng-click="vm.sendMessage()"><i class="fa fa-envelope-o"></i> {{ 'MAILBOX.SEND_MESSAGE' | translate }}</button>
				<button class="btn btn-default btn-xs" ng-click="vm.buyHeart()"><i class="fa fa-heart"></i> {{ 'USER.BUY_HEART' | translate }}</button>
				<button class="btn btn-default btn-xs" ng-click="vm.addFriend()"><i class="fa fa-users fa-fw"></i> {{ 'USER.ADD_FRIEND' | translate }}</button>
				<button class="btn btn-default btn-xs" ng-click="vm.blockUser()"><i class="fa fa-ban"></i> {{ 'USER.BLOCK_USER' | translate }}</button>
				<report-button type="user" id="vm.user.id" body="vm.user.username"></report-button>
				<button ng-if="vm.currentUser.class >= 8" ui-sref="cheatlog({userid: vm.user.id})" class="btn btn-xs btn-default"><i class="fa fa-search"></i> {{ 'ADMIN.CHEAT_LOG' | translate }}</button>
			</td>
		</tr>
		<tr ng-if="vm.currentUser.class >= 8">
			<td class="text-right tdBold">
				<button class="btn btn-default btn-xs" ng-click="vm.toggleSnatchLog()">
					<i class="fa fa-bars"></i> {{ 'TORRENTS.SHOW_SNATCH' | translate }}
				</button>
			</td>
		</tr>
		<tr ng-if="vm.showSnatchLog">
			<td colspan="2">
				<div ng-show="vm.showSnatchLog && !vm.snatchLog" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
				<table class="table table-striped table-hover table-nowrap text-center" ng-show="vm.showSnatchLog && vm.snatchLog">
					<thead>
						<tr>
							<th class="text-left">&nbsp;{{ 'TORRENTS.TORRENT' | translate }}</th>
							<th style="width: 75px;" translate="TORRENTS.PORT"></th>
							<th style="width: 160px;"><a class="whiteLink" href="" ng-click="snatchLogOrderBy='ip'; reverseSort = !reverseSort" translate="TORRENTS.IP_PORT"></a></th>
							<th style="width: 100px;"><a class="whiteLink" href="" ng-click="snatchLogOrderBy='uploaded'; reverseSort = !reverseSort" translate="TORRENTS.UPLOADED"></a></th>
							<th style="width: 100px;"><a class="whiteLink" href="" ng-click="snatchLogOrderBy='downloaded'; reverseSort = !reverseSort" translate="TORRENTS.DOWNLOADED"></a></th>
							<th style="width: 100px;" translate="TORRENTS.START_STOP_FINISHED"></th>
							<th style="width: 100px;"><a class="whiteLink" href="" ng-click="snatchLogOrderBy='agent'; reverseSort = !reverseSort" translate="TORRENTS.CLIENT"></a></th>
							<th style="width: 125px;"><a class="whiteLink" href="" ng-click="snatchLogOrderBy='finishedat'; reverseSort = !reverseSort" translate="TORRENTS.SNATCHED"></a></th>
							<th style="width: 125px;"><a class="whiteLink" href="" ng-click="snatchLogOrderBy='seedtime'; reverseSort = !reverseSort" translate="TORRENTS.SEED_TIME"></a></th>
						</tr>
					</thead>
					<tbody>
						<tr ng-repeat="snatch in vm.snatchLog | orderBy:snatchLogOrderBy:reverseSort track by snatch.id">
							<td class="text-left">
								<table class="table table-striped table-hover table-nowrap noshadow">
								<tr>
									<td style="width: 57px; border: 0px; padding: 0px;">
										<img class="categoryImage category{{ ::snatch.torrent.category }}" />
									</td>
									<td style="border: 0px; padding: 0px;">
										<torrent torrent="::snatch.torrent"></torrent>
									</td>
								</tr>
								</table>
							</td>
							<td ng-bind-html="::snatch.connectable | connectable"></td>
							<td><a ui-sref="admin-search({ip: snatch.ip})">{{ ::snatch.ip }}</a>:{{ ::snatch.port }}</td>
							<td>{{ ::snatch.uploaded | prettysize }}</td>
							<td>{{ ::snatch.downloaded | prettysize }}</td>
							<td>{{ ::snatch.timesStarted }}/{{ ::snatch.timesStopped }}/{{ ::snatch.timesCompleted }}</td>
							<td>{{ ::snatch.agent | prettyAgent }}</td>
							<td>{{ ::snatch.finishedat | dateDifference }} {{ 'MAILBOX.AGO' | translate }}</td>
							<td>{{ ::snatch.seedtime*1000 | dateDifference:0 }}</td>
						</tr>
					</tbody>
				</table>
			</td>
		</tr>
		<tr ng-if="vm.user.requests > 0">
			<td class="text-right tdBold">
				<button class="btn btn-default btn-xs" ng-click="vm.toggleRequests()">
					<i class="fa fa-bars"></i> {{ 'USER.SHOW_REQUESTS' | translate }}
				</button>
			</td>
			<td class="text-left">
				<span translate="USER.UPLOADED_REQUESTS" translate-value-x="{{ ::vm.user.requests }}"></span>
				<div ng-show="vm.showRequests && !vm.requests" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
				<div ng-show="vm.requests && vm.showRequests">
					<torrents-table torrents="::vm.requests" col-download="true" col-size="true" col-comments="true" col-seeders="true" col-leechers="true"></torrents-table>
				</div>
			</td>
		</tr>
		<tr ng-if="vm.user.torrents > 0">
			<td class="text-right tdBold">
				<button class="btn btn-default btn-xs" ng-click="vm.toggleTorrents()">
					<i class="fa fa-bars"></i> {{ 'USER.SHOW_TORRENTS' | translate }}
				</button>
			</td>
			<td class="text-left">
				<span translate="USER.UPLOADED_TORRENTS" translate-value-x="{{ ::vm.user.torrents }}"></span>
				<div ng-show="vm.showTorrents && !vm.torrents" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
				<div ng-show="vm.torrents && vm.showTorrents">
					<torrents-table torrents="::vm.torrents" col-download="true" col-size="true" col-comments="true" col-seeders="true" col-leechers="true"></torrents-table>
				</div>
			</td>
		</tr>
		<tr ng-show="vm.user.peersSeeder || vm.user.peersLeecher">
			<td class="text-right tdBold">
				<button class="btn btn-default btn-xs" ng-click="vm.togglePeers()">
					<i class="fa fa-bars"></i> {{ 'TORRENTS.SHOW_TRANSFERS' | translate }}
				</button>
			</td>
			<td class="text-left">
				<span translate="USER.PEER_ACTIVITY" translate-value-seeding="{{ ::vm.user.peersSeeder }}" translate-value-leeching="{{ ::vm.user.peersLeecher }}" translate-value-total="{{ ::vm.user.peersSeeder + vm.user.peersLeecher }}"></span>
				<div ng-show="vm.showPeers && !vm.seeding" class="fa-spinner fa-spin fa-3x fa-fw spinner"></div>
				<div ng-show="vm.seeding && vm.showPeers">
					<br />
					<b>{{ 'USER.SEEDING' | translate }}:</b>
					<user-peers peers="vm.seeding"></user-peers>
					<br />
					<b>{{ 'USER.LEECHING' | translate }}:</b>
					<user-peers peers="vm.leeching" ng-show="vm.leeching && vm.showPeers"></user-peers>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<p style="white-space: normal;" ng-bind-html="::vm.user.info | bbCode"></p>
			</td>
		</tr>
	</table>
<br />
</div>
</div>
